/*
 * @Project Name: demo
 * @File Name: DruidConfiguration.java
 * @Package Name: com.example.demo.config
 * @Date: 2017年8月10日下午2:33:44
 * @Creator: wangjian-358
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package com.sm.shoplook.config;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;

/**
 * DruidConfiguration
 * @author chenpy-1072
 * @date 2017年8月10日下午2:33:44
 * @see
 */
@Configuration
public class DruidConfiguration {

	@Primary
	@Bean
	@ConfigurationProperties(prefix = "spring.datasource")
	public DataSource druidDataSource() {
		DruidDataSource druidDataSource = new DruidDataSource();
		List<Filter> filters = new ArrayList<>();
		filters.add(wallFilter());
		druidDataSource.setProxyFilters(filters);
		return druidDataSource;
	}

	@Bean
	public WallConfig wallConfig() {
		WallConfig wallConfig = new WallConfig();
		wallConfig.setMultiStatementAllow(true);
		return wallConfig;
	}

	@Bean
	public WallFilter wallFilter() {
		WallFilter wallFilter = new WallFilter();
		wallFilter.setConfig(wallConfig());
		return wallFilter;
	}
}
